<?php

namespace App\Livewire;

use App\Enums\BookStatus;
use App\Enums\OrderStatus;
use App\Models\Book;
use App\Models\BorrowRecord;
use App\Models\Order;
use Livewire\Attributes\Layout;
use Livewire\Component;

#[Layout('layouts.app')]
class OrderPage extends Component
{
    public  $tabs;
    public  $status = 'all';
    public function mount()
    {
        $this->tabs = OrderStatus::cases();

    }
    public function render()
    {
        return view('livewire.member-order',[
            'orders'=>$this->getPageData()
        ]);
    }

    public function refundable(Order $order,$remark)
    {
        $order->update([
            'status'=>OrderStatus::REFUND_ING,
            'remark'=>$remark
        ]);

    }

    public function getPageData(): \Illuminate\Contracts\Pagination\LengthAwarePaginator
    {
        $query = Order::query()
            ->where('user_id',auth('frontend')->id());
        if ($this->status != 'all'){
            $query->where('status',$this->status);
        }
        return $query->orderByDesc('created_at')
            ->paginate(10);
    }
}
